package com.ruoyi.active.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.active.domain.Active;
import com.ruoyi.active.service.IActiveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动信息Controller
 * 
 * @author author
 * @date 2024-06-30
 */
@RestController
@RequestMapping("/ruoyi-active/active")
public class ActiveController extends BaseController
{
    @Autowired
    private IActiveService activeService;

    /**
     * 查询活动信息列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-active:active:list')")
    @GetMapping("/list")
    public TableDataInfo list(Active active)
    {
        startPage();
        List<Active> list = activeService.selectActiveList(active);
        return getDataTable(list);
    }

    /**
     * 导出活动信息列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-active:active:export')")
    @Log(title = "活动信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Active active)
    {
        List<Active> list = activeService.selectActiveList(active);
        ExcelUtil<Active> util = new ExcelUtil<Active>(Active.class);
        util.exportExcel(response, list, "活动信息数据");
    }

    /**
     * 获取活动信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-active:active:query')")
    @GetMapping(value = "/{activeId}")
    public AjaxResult getInfo(@PathVariable("activeId") Long activeId)
    {
        return success(activeService.selectActiveByActiveId(activeId));
    }

    /**
     * 新增活动信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-active:active:add')")
    @Log(title = "活动信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Active active)
    {
        return toAjax(activeService.insertActive(active));
    }

    /**
     * 修改活动信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-active:active:edit')")
    @Log(title = "活动信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Active active)
    {
        return toAjax(activeService.updateActive(active));
    }

    /**
     * 删除活动信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-active:active:remove')")
    @Log(title = "活动信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{activeIds}")
    public AjaxResult remove(@PathVariable Long[] activeIds)
    {
        return toAjax(activeService.deleteActiveByActiveIds(activeIds));
    }
}
